﻿using DeviceManager.DB;
using DeviceManager.DB.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace VirtualReportDeviceStatus
{
    class Program
    {
        static void Main(string[] args)
        {
            Random rdom = new Random((int)(DateTime.Now.Ticks % int.MaxValue));
            ManagerDBCtrl manager = ManagerDBCtrl.GetMng();
            List<DeviceNode> nodes = manager.GetAllDevices("");
            while (true)
            {
                foreach(var de in nodes)
                {
                    if (de.DeviceIsMaintain == 0)
                    {
                        //没有维护的设备
                        de.DeviceVoltage = rdom.Next(Math.Abs((int)de.DeviceMinVoltage - 10), (int)de.DeviceMaxVoltage + 10);
                        de.DeviceElectricCurrent = rdom.Next(Math.Abs((int)de.DeviceMinElectricCurrent - 10), (int)de.DeviceMaxElectricCurrent + 10);
                        de.DeviceTemperature = rdom.Next(Math.Abs((int)de.DeviceMinTemperature - 10), (int)de.DeviceMaxTemperature + 10);
                        de.DeviceHumidity = rdom.Next(Math.Abs((int)de.DeviceMinHumidity - 10), (int)de.DeviceMaxHumidity + 10);
                        de.DeviceLastUpDate = DateTime.Now;
                        if(manager.UpDateDeviceStatus(de))
                        {
                            Console.WriteLine(string.Format("更新设备信息->{0}", de.DeviceName));
                        }
                    }
                }

                ///5分钟模拟一次数据
                Thread.Sleep(1000 * 60 * 5);
            }
        }
    }
}
